//
//  LoadData.m
//  食为天
//
//  Created by lanou3g on 14-8-17.
//  Copyright (c) 2014年 三个屌丝. All rights reserved.
//

#import "LoadData.h"
#import "JTCSM.h"
 static LoadData *load = nil;
@implementation LoadData
+ (instancetype)object{
    @synchronized(self){
        if (load == nil) {
            load = [[LoadData alloc]init];
        }
    }
    return load;
}


//Post异步请求
- (void)loadDataPostAsynchronousWithURL:(NSString *)url withDict:(NSDictionary *)dict superView:(UIView *)fahter Block:(LoadDataBlock) block{
    [df showWaiting:fahter];
    NSLog(@"-----%@-----%@",KURLPOSTHeadr(url),dict);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    // 2.设置非校验证书模式
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    manager.securityPolicy.allowInvalidCertificates = YES;
    [manager.securityPolicy setValidatesDomainName:NO];

    [manager POST:KURLPOSTHeadr(url) parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"%@",responseObject);
        if (KResponseCode==200) {
         block(responseObject);
        }
        if (KResponseCode == 600) {
            KUSERDEFAULTRemoveAll(KuserInfo);
            KUSERDEFAULTRemoveAll(Khtml_user);
            [df gotoLoginVC];
        }
        [df hideWaiting:fahter];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"----%@",error);
        [df hideWaiting:fahter];
        KUSERDEFAULTRemoveAll(KuserInfo);
        KUSERDEFAULTRemoveAll(Khtml_user);
         [df gotoLoginVC];
    }];
    
    
}



@end
